Use the open() and writeline() commands.

code:

$index = 0
$groups = ""

$cr = chr(13)+chr(10)
$file = "groups.txt"

if exist($file) = 1 del $file endif

do
$groups = $groups + enumgroup($index) + $cr
$index = $index + 1
until enumgroup($index) = ""

$nul = open(1,$file,5)
$nul = writeline(1,$groups)
$nul = close(1)

? "@curdir$file was created that contains all global groups that @userid was a member of"