This is how the function looks in my game:
https://github.com/Duion/Uebergame/blob ... #L320-L321
I put it into the on sleep method in the options dialog, so every time the options dialog is closed the settings are saved automatically, so settings can never get lost.
The function will export any "$pref::" value which includes all settings also video settings. Second argument is the path and filename to write, where i used a custom function to get the home path, but you can directly write a file path there.
Control bindings may work for you, since they are saved in a different function to a different file, as you can see in my example as well.
A source of error may be that for certain settings you forgot to write into script to save them into pref values, it happened to me a few times. The export function only exports the pref values that have been changed, if you forgot to link the button in the options menu to change the values of course they will not be saved.