Ensure file handle is closed using with statement

This changes ensures the file handle is always closed in `setup.py`.