A properly written program never needs to reset itself. And if the program should crash it won't be able to reset itself unless you enable the Watch Dog Timer.
I presume xxx.flush() waits until all the data is written to the file. is that what you want?
...R