The series of events need to be in a certain order and can only be done in an idle state so you will prob need to run mc.mcCntlEnable(inst, 0) before writing to the ini, then re-enable with mc.mcCntlEnable(inst, 1)
local inst = mc.mcGetInstance()
mc.mcCntlEnable(inst, 0) -- disable controller
mc.mcProfileWriteInt(inst, "Motor0", "CountsPerUnit", 1000 ) -- what we require in our ini
mc.mcProfileFlush(inst) -- force the changes to be written
mc.mcProfileReload(inst) -- reload the changes
mc.mcCntlEnable(inst, 1) -- re - enable controller
Although the above code works fine, there are other factors to take into account like the motion controller will need to know that your settings have changed ( take a look at mcCntlConfigStart and mcCntlConfigStop ) about this.
DazTheGas