Bugfix when creating configuration files

Writing {} instead of empty file
Creating file with correct permission before writing