Try this, I have a huge contact list so testing it fully on mine would take a billion years. But the initial tests work
These sort of script are really only handy on small lists as the overhead with all the repeating is exponential the larger they get.
property orphan : "Orphans"
tell application "Contacts"
if not (exists group orphan) then
(*Create the new group*)
make new group at the end of groups with properties {name:orphan}
end if
--set thePeople to first person whose first name is "TEST"
(*get all entries*)
set thePeople to every person
(*iterate through the entries*)
repeat with i from 1 to number of items in thePeople
(*get the entry*)
set this_person to item i of thePeople
(*get the entries group list *)
set inGroup to name of group of this_person
if inGroup is {} then
(* entry is not in any group*)
add this_person to group orphan
save
else if inGroup contains "Orphans" and inGroup is not equal to {"Orphans"} then
(*if entry is already in a group/s then check it is not also in¬
Orphans or only in orphans*)
(* entry is in orphans and another group so remove it from orphans*)
remove this_person from group orphan
save
end if
end repeat
save
end tell