Append /opt/bin to $PATH
On my system [Gentoo] /opt/bin contains nvidia-smi, which the superuser $PATH for some reason didn't contain. Appending this directory path to path during the script would fix it not finding nvidia-smi. Or just prompting you to make a symlink from it to /bin/nvidia-smi