Reading from and writing to textfiles

I need help with reading and writing to textfiles. I need to save and load data to and from variables. I know how to read from text-files, but not how to write to them.

The text-files should work as a “database” for the high-score in a game, I can´t use php cause the computer running the game won´t be online all the time.

thanks in advance // k