Proper way to remove unused linked Group data-blocks
Groups are intentionally not garbage collected, (so they have to be removed manually). Only a few kinds of data-blocks behave this way, Scene's are another example.

As a user, you can select them in the outliner and unlink them, but there is no way to remove single user groups other then to script this as you have done.

For details see the reference manual.