Add try/finally for closing the file pointer.