Ensure file handle is closed using with statement

Hey Jonathan, this change ensures the file is closed by using the with statement (similar to the function below it).