Well, you'd have to use two files. One file that actually gets executed and a temp file. The temp file would be used when you just want to add a line to it. So on the line addition, you'd read in all the lines from the exec file until you get to a certain point, then write them to the temp file and add your new line. then close off the file and write all the temp content to the exec'd file.
About the abort, I'm sure it's possible but I'm not gonna spell that out for you.