I'd recommend sooner, Damian Conway - Perl Best Practices also recommend such approach, I guess its valid for other languages too. The only option for not releasing any resource (after its not required any more) is when the release process itself consumes much resources. For instance any garbage collector delays memory releasing because it could be cpu and time consuming.
What if the file is not closed until the very end?
for example any unhanded exception will probably halt your program and any buffered data won't be flushed to a file.