Close templated files before trying to remove them. Fixes #28