In simpler terms, you want a list of all the groups in which a user ("username") is a member. Is that right? Then put those names into two files, one for all groups whose name begins with "DMS" and another one for all groups show names don't begin with "DMS". Is that also right?
Something like this might be what you want (NOTE: I haven't run this!):
$dms = @()
$username = 'xyz'
$dmsfile = c:\junk\dmsgroups.txt
$nondmsfile = c:\junk\nondmsgroups.txt
Get-ADPrincipalGroupMembership -Identity $username |
Select-Object -Property name |
Sort-Object |
ForEach-Object{
if ($_.name -like 'DMS*'){
$dms += $_.name
}
else{
$_.name
}
} | Out-File $nondmsfile
$dms | Out-File $dmsfile