defaults write com.apple.screencapture location folder_name_here
Save screenshots to the 'Screenshots' folder (inside iCloud Drive)
defaults write com.apple.screencapture location ~/Library/Mobile\ Documents/com~apple~CloudDocs/Screenshots
Worked fine for me. I did make the folder before trying it tho. So a
mkdir -p ~/Library/Mobile\ Documents/com~apple~CloudDocs/Screenshots
might be needed on first run.
For the permissions maybe
chmod u+rw ~/Library/Mobile\ Documents/com~apple~CloudDocs/Screenshots
helps?
Works totally fine on OSX Serria without any issue.