If you make the open/write/close fairly atomic, i.e. not spread throughout code but a single function, you can simply open a file for append and write to it and close. if the file doesn't exist it will get created, and if exists it will be appended to. make sure to close just after the write.
the hardest line to type correctly is: stty erase ^H