That little script works fine on a sample I put together. Your document may have some structure that I’m not aware of, but what the script has to do is simple so I had expected it to work. I also don’t understand the error message, I can’t reproduce it.
If the numbers aren’t always plain digits, and if brackets are used for footnote references only, you could try replacing line 2 with this one:
app.findGrepPreferences.findWhat = '[.+?]';
As to all the backslashes, to use a basckslash as a literal you have escape it, as the saying goes. Thus, in InDesign’s Find/Change window you’d use \[.+?\], but when you define a string with that GREP, you have to use ‘[.+?]‘. If you don’t, and use '\[.+?\]', then \[ and \] will be interpreted as special characters, not as the string \[. Compare that with e.g. $: it has a special meaning in GREP (‘end of string’) and in order to use it literally, as a currency symbol, you have to escape it and use \$.
Peter