10.4 Closing Filehandles
Filehandles are closed using the .close. operator and with the name of the filehandle to be closed as the argument:
The general recommendation is to close a filehandle once you have finished using it in your program. There are a couple of reasons for this. Firstly it is good behavior to close file when you have finished working with it to avoid unnecessary use of system resources. Secondly, it causes the operating system to flush the output buffers to the file thereby ensuring that all the data gets written to the file or stream. An unexpected system crash while you have a filehandle open could result in a truncated data file.