Ensure file is closed by using with statement

Unlike the other `open()` calls, this file wasn't being closed. This commit ensures the file is closed.