Ensure file is closed by using with statement

This ensures that the file is always closed by using the with statement.