in reply to Removing leading whitespace from a file?
You open the same file twice. The open to write will clobber the file, so it's empty when it's read.
Instead, open a new filename to write, and rename it after you're done.
After Compline,Zaxo