Following enhancements: 1. Don't write that many temporary files 2. Compare the created configuration file against the existing one. Copy and restart only if the configuration file is different.