Generally speaking, there are multiple reasons for why it's a very good practice to close a file object once you're done reading/writing. Some of them are relevant mostly for large-scale programs.
One important issue that is probably affecting your program is that the content that a program writes to a file is usually not written immediately, but kept in a temporary memory buffer, in order to reduce the number of (expensive) disk accesses. The buffer's contents is guaranteed to be written to the disk only when the file is closed. Ideally, this would happen when the programmer (you) close the file; if you don't, the OS will close it for you when the program exists (or at least it should).
So I'm guessing that you tried reading the file before you closed it or exited the interpreter, and therefore the file was empty / included only partial content.