This appears to be a Blizzard bug. The line of code that's causing it is as follows...
SaveBindings( GetCurrentBindingSet() or 1 );
Which would imply that GetCurrentBindingSet() is returning an invalid value. I'm discussing it with Blizz now and we'll see if we can run down what's happening.
Have you chased this down? I've tried bypassing the problem with code like
If GetCurrentBindingSet() == 2 then SaveBindings(2) Else SaveBindings(1) end
but, while the error went away, what happens is that the keybindings don't get applied at all (in at least some cases). It has to be returning a value other than nil, 1, or 2 for your code to get an error (I had tried the same coding and ran into the same error).
One of my posters noted that it only happened on logons other than the first. I was able to recreate the error on another account.
I went into keybindings and noted that the affected character had the checkbox for Character Specific Key Bindings checked and zero keybinds. I then did /script ReloadUI() and checked again, the keybinds were there, but the checkbox was not checked. I checked the box again and since then I haven't been able to reproduce the error on that account.