Thanks for reaching out to Q&A.
The code works in your local machine as you have write permissions on the shared directory in your desktop. However, there are restrictions in the Functions file system as it is a sanboxed environment.
File systems restrictions and considerations : https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#file-system-restrictionsconsiderations
The long term solution for your problem is to download and move the files to an Azure storage account.
I hope this helps! Feel free to reach out to me if you have any further queries or concerns.