Line breaks are stripped by ckeditor after saving a node programmatically
I would try disabling the Advanced Content Filter in CKEditor as a starting point. 

In a typical scenario, most people are exclusively using CKEditor to set and update their field values, so the content stays exactly the same between viewing and editing the node, which is the behavior you're expecting.

However, since you are setting the field programmatically, when you edit the node it's the first time CKEditor is seeing the field value (i.e. the first time CKEditor filters are being run). CKEditor will filter and "correct" your HTML to its standards, so it's not safe to assume your field value will be untouched if it's the first time CKEditor is seeing it.

Your options are to 1) tweak how CKEditor filters your HTML, or 2) conform the HTML you're programmatically saving to the CKEditor standards.