Just to follow up on the above Runtime Error while attempting to look up writeLines on a file... that's because FileHandle doesn't have a writeLines method. It has write and writeLine, but not something to write all lines. The intent is that if that's all you want to do (read or write all lines at once), you don't bother creating a FileHandle at all; you just use the file.writeLines and file.readLines methods directly. FileHandle is meant for when you need finer control, reading or writing just part of a file for example.
(The other gotcha with FileHandles is that you must remember to call .close on them. You did that correctly, but this is still another reason to prefer the global file methods.)
I've just checked the docs and they are correct on this point, but clearly it could all be a bit clearer.