I am trying to write strings to a file but all the strings are being written to the file once the script is terminated.
To make my problem clear, in the below code I