Close temporary files before deleting, on Windows if they are not explicitely closed there are not deleted. Thanks to spritchard for the patch.