Oh, I misread your code at first... I believe you should call g_settings_sync ()
if you want to ensure your changes are written to disk. Apparently if you run without a mainloop (like in your example case) this is really required to get things on disk at all.
So, just to be clear: a normal application with a glib mainloop will not need (and shouldn't really use) a sync-call.