It may not be exactly related to your requirement.
I'm trying to convey that when you see that file is not updated, there may be a case that the file handle not selected for automatic flushing. In such a case, you can use the select to make the file updation proper.
This is just to give you some clarification in the "files not altered" matter.
It isn't relevant (yet) since you aren't writing to a file in your example. Once you do get that straightened out, autoflush can be useful if you are trying to look at your output file while the program is still running.