Why would you do such a thing when you can use something like Kermit (which has been around for over 40 years)....
Eventually, Data I/O made it an official part of the LogicPak.
It was a VT-100 terminal emulator for the PC, with a side feature of capturing the received data to a file, or writing the contents of a file to the serial port.