Why is object.origin_set(type='ORIGIN_CURSOR') not working?
You are right. To set object origin, you must be in object mode. You can also try using bpy.ops.object.mode_set(mode='OBJECT') to change to object mode.