That's a perfectly functional trigger, although the mechanics of unit groups and locations means that it will be pretty memory-leaky. If cast often, it may cause the game to lag and will likely cause a long garbage-collection period at the end of the map.
However, doing it with jass variable destruction and locals is substantially more difficult, so if this one works well, I'd advise you to use it.