Wrap the file processing in a try/finally to ensure that the file handle is always closed properly.