Just try the following.

Close the file after writing string and then open back to write and see what is the output?