Explicitly close file on test cleanup

Fixes windows test failures.