Automatic write of config file

This piece of awesomeness writes the config file if possible. Otherwise it outputs the config as had.