That's a relief to know. I traced the problem, it was not in the code. My text editor was not showing the final newline. When I used cat on the file, I could see that there was indeed a new line there.