Fix ResourceWarnings when script tests fail.

If running one of the script tests fails, then Python 3 will print out a `ResourceWarning` because the file is opened and read, but not closed.