I think it can be done with three files: the target, a "log" file and a temporary:
when starting the program, if the log file exist => cat it to the target and then remove it
to modify the file, write the data to a temporary file, them rename the temporary file to be log file, cat the log over the target and finally remove the log file.