This will never work. You have to create cron job for user www-data. To do so, type
sudo -u www-data crontab -e
After this enter your line from above without sudo and user and save it:
*/5 * * * * php /var/www/nextcloud/occ files:scan --path="/XYZ/files/XYZ"
The aim of my script is to get info about all your shares and rescan them. Please check documentation repo, supported Synntax. I believe you simply did not configure it correctly.