No, I don't think I can think of any way to avoid this...
What I meant by the comment was, rather than read the entire file at once, and then make the change, we make changes line by line, but I see how this could be misleading. Will fix!