Fix a problem where test data files cannot be unlinked on Windows

The handles of generated test data files were left open, which can lead to problems on Windows based systems where files cannot be deleted, and `unlink()` throws "*permission denied*" errors.