Ensure file handle is closed by using with statement

This ensures file handle is closed automatically (similar to other files).