The previous monks' questions are good ones. Please take some time to answer them.
My thoughts are that change the file name and the folder you're writing to. Temp is pretty common folder name and data.txt is also fairly common file name. It's conceivable that another process is interfering. Hence why I suggest trying to write to a different location with a different name. See if that changes it things. If it does, you know it has to do with your environment and you could do with some investigative work.