The current code cannot cope if text that is underlined or has a background colour contains a \write node or an \insert
This means footnotes, new font generation (when logged) and probably other things too cause breakages when underlined.
The work-around is to end any style that uses underlining or background colour before starting a note, etc.
Longer term, the box-unwrapper code used by both of the above needs a rewrite.