Ensure file handles are closed using with statement

This change ensures the file handles are properly closed in setup.py.