@Soma Sekhar Turpinti The function app root is usually not writable when running from a package (which is common for most deployment paths). That is why your code works locally.
When running on Azure, use the Path.GetTempPath method to get the temporary path.
If you are running on a Linux plan, you could mount file shares.