Before appending, check the last character and add a newline if it's missing:
tail -c1 robots.txt | od -c
If that doesn't show \n, run echo >> robots.txt first. Also check with curl after any edit, since that shows exactly what crawlers receive. Our
audit tools include a robots.txt and sitemap checker.