According to the documentation, mw.text.nowiki() escapes all chars that have special meaning in wikitext. An exclamation point "!" is part of the table syntax, so it should be replaced when it starts a new line. Example wikitext:
{| ! heading |}
Example of problem in practice:
On https://sv.wiktionary.org/wiki/Modul:grammar-table/test we have been forced to create a workaround for this issue.