Writing to a file is a bit like building houses on a street. It's reasonably easy to walk down to the end of the street and start building a new house. However, it's significantly more difficult to "insert" a new house at the start - you have to pick up and move every other house one section down. Not only that, but everybody's address changes too.
By using "a"
to append to the existing file, you're building a new house at the end of the street. To insert at the start, you will have to do something like:
- Open a new file
- Write your comment to the new file
- Copy the entire contents of the old file to the end of the new file
- Close the new file
- Move the new file on top of the old one, replacing it