in reply to Clobber instead of append

You need to seek back to the beginning to write to the beginning. You're leaving the stream pointer at the end of the file, so you want to reset it. You may also want to look at truncate because you'll be removing characters, and you'll want to remove excess file.

It is simpler, however, to write to a new file, delete the original, and rename the new file to the old name. Or, rather than delete the original, rename it to a backup name. Much safer, too.