Some improvments with file generation

1. Write file only when it does not exist
2. Delete old generated files