defer file close to fix issue #604

closing the file too early keeps the profiling from writing out to the file.