Collapse config file check to one regexp.

Also noticed the file write was inside the loop for each line in the file, so I moved it outside and made it write only if there are any config files changed.