I tried a version of your code and it works.
I could not duplicate your problem (of adding a line at the end of the file), but I suspect that what it is doing is reading all the file into the 1st element of the array. I think the end of lines in the file are not being recognized. To check this I would add the following after the file() statement -
Another possibility is that the file is still open (there is no fclose($f); following the file() statement) when you try to open it for writing. On my system this did not cause a problem. On your system, who knows?
Another problem is in your checkline variable. It changes between CheckLine and Checkline several times. This should have caused an error (it did on my system), but the error level setting would affect if you get an error.
Lastly, there could be a problem with the file permissions. As always, function calls should have error checking and reporting done on the results.
Here is the slightly modified version of your code that I tested with -