hi
Same issue as you.
$user take username in Nextcloud user list. If you look username in nextcloud it’s the SID and not the AD username, so when you use $user for folder it search folder name with SID.
If you create a folder with the SID it’s working…
I’m interest If you find a solution