Fixed #21122 -- Improved clean up of test temp directory on Windows

- Fixed test that didn't close the files it opened
- Caught and handled exception when temp directory cannot be removed