Only write hosts file if change and clean up