Script working only inside blender
Object/edit mode is not related to UI.

I think one issue here is that some add-ons do not handle their init code correctly (assuming keyconfigs are always present in wm, which iirc is not the case when Blender is started in background mode, a lot of things get disabled then).

So a first thing to try is to start blender with --factory-startup option, which only enables official add-ons (which are supposed to behave correctly).

Second point is that, afaics, you do not select anything in your mesh before calling the dissolve operator? So if no faces are selected in existing objects, dissolve cannot merge anything…