Create a field group in a plugin
Just a hunch and not tested, but don't do this:

$group-&gt;id   = '';


My guess is by explicitly setting that to an empty string, Craft thinks it's dealing with an existing record and not a new one.