Switching ui_scale with script doesn't work

so, i’m trying to switch ui_scale with script:

local pref = app.preferences.general 
local scale = pref.ui_scale 

if scale == 1 then 
	pref.ui_scale = 2 
elseif scale == 2 then 
	pref.ui_scale = 1 

i can see that edit → preferences: UI Elements Scaling value is changing, however ini file itself doesn’t get modified and the change isn’t applied.
i tried to use both app.refresh and app.command.Refresh but it made no difference

also, is there a reason why changing ui scaling creates grid settings entry in undo history?