command have no knowledge of what is already in the file, it does not magically remember that you already added a heading, it assumes you are running from the start.
You need to keep a record of the line count yourself somewhere, either in this file or another, or read the whole file each time to figure out what $- should be.