Write out new host entries one line at a time

Code for issue https://github.com/saltstack/salt/issues/4531