Are you using WYSIWYG editing at all? If so, then you should be aware that WYSIWYG is not compatible with clean code, and that is pretty much definitely the problem.
If you aren't using WYSIWYG editing at all, Sigil should NOT be editing the code. (Aside from pretty print, which fixes up entities and doctypes and xml structure, but doesn't change HTML or CSS. Also, you can turn that off.)
am pretty sure even opening up Book view will introduce some weird changes. Personally, I prefer the
calibre editor. It allows you to work wholly in code view, without the temptation of Book view, and doesn't load the whole book in the editor on startup, and has global undo and checkpoints, and lots of other cool features.