>>Can you write to the file directly without using a variable and strtofile using fwrite function?
>
>I could but I would expect this to take even more time, because as the file grows it would have to move it around quite a lot?
No, this is going to be a better performing solution. Using low-level file operations would be quicker.
If it's not broken, fix it until it is.
My Blog