The way I would go about this is to load all the lines of the text file
in a list, and then iterate through that list, changing the values of the
list as you go along. Then at the very end (when you get to the last line
or whenever you want), you will write that whole list out to the file with
the same name, so that way it will overwrite the old file.