Character encoding and type coercion errors are so common. But a lot of bugs also come from programs trying to do “the right thing”. Like in OP’s case: they are just trying to import some data and maybe the data was never even intended to be interpreted as utf8, but the tool they are using to remove the commands wants to treat it that way. Sometimes the safest thing to do is to just assume data is binary until you care otherwise.
The Unicode standard allows, but recommends against, adding a BOM for utf8 files. Utf8 does not need them.
I’ve only seen Microsoft tools adding that, and it breaks some parsers.
Please don’t add BOM to utf8 files unless for some reason you need them.