Make sure there's a line break before writing new key

* Add test case which verifies the occurrence of #7409.
* Make sure there's a line break before writing new key. Fixes #7409.