core: be sure to close tempfile handle so Windows can delete it