fix #13917 - add linebreak if there isn't yet one

If a file didn't yet have a linebreak at the end we wouldn't add
our new line on a new line rather at the end of the last line.

This commit fixes that bug, furthermore it ensures that while
running all the "add" specs all the tmpfile exists, as this is
what we assume in our current codebase.

This is an alternative implementation to GH-62