Hmm, so you just need to write a string to a file via a link?
Hidden Content
You must
[To see links please register here]
or
[To see links please register here]
to view this content.
Not exactly sure if that's what you were looking for as I don't completely understand your request. That's how you'd do it via file, and I'm not sure if PHP File I/O also includes seeking like in Python. If it does, and you want to be at the front of the program you'd do seek(0) or some variation in it with PHP.
You kept saying you were overwriting the file, and this is because when you open up a file with the 'w' or 'w+' permissions, it will automatically truncate all contents within it. Every language has it (Python, PHP, C++, etc). It's an OS problem, not the language itself. If you append the file, it doesn't delete the contents and that's the only way I really get around it.
edit;
If this doesn't work, or doesn't help you at all, please tell me. I'll keep looking into it so I can help you out as I want to know for my own benefit. Surprisingly, I can't get my head wrapped around it, but I'll try my best and research later if the information I've provided isn't beneficial to you at all. Though, it should be in the ballfield, so you may be able to get it done.