You create a copy of the file by reading in one line at a time and outputting to the new file one line at a time.
When you read in "deletethis", you close both files, delete the original file, rename the new file to the name of the original file.
OH thank you. I am so stupid XD