in reply to
You need to write the file back out. What you have (assuming your regexp is correct and all of that) just changes the file in memory, not on the disk. It is also important to note that the global option is unnecessary in your situation (if your replacing a whole line why would you need to repeat). You will also replace oldline with new line other places in the file. If you have duplicate lines and want to keep some this will get hard for you.
That said here is a way to do this. You need to store all of the lines in memory (check out push for this), change the one you need and write it back to the file. Also you are just going to append to the file the way you have your code now. If that is your intention you have it correct, if not read the documentation on open You should also be closing the file, but you are probably doing that further down in your code.