Close template files after writing so that they get flushed to disk. Relying on the process closing to flush IO buffers breaks running in 'daemon' mode.