Saving Files to Desktop no longer works (Sonoma)? Entitlements?

Hello, I need some help. I have an apparent problem with entitlements on a silicone mac on MacOs Sonoma. The following sample code works without problems on the simulator, but not when build for macOS:

local path = system.pathForFile("hello_world.txt", system.DocumentsDirectory)

local file, errorString = io.open(path, "w")

if not file then
    print("File error: " .. errorString)
else
    file:write("hello world")
    io.close(file)
    print("File written successfully")
end

file = nil

local lfs = require("lfs")
local function moveFileToDesktop(fileName)
    local doc_path = system.pathForFile(fileName, system.DocumentsDirectory)
    local desktop_path = os.getenv("HOME") .. "/Desktop/" .. fileName

    local result, reason = os.rename(doc_path, desktop_path)
    if result then
        print("File moved to desktop successfully.")
    else
        print("Failed to move file: " .. reason)
    end
end

moveFileToDesktop("hello_world.txt")

I get this alert from my macOS app: “/Users/yankopopov/Library/Containers/FileSave/Data/Library/Application Support/FileSave/Documents/hello_world.txt: Operation not permitted”. Apparently the file is created in the App’s sandbox Documents folder, but can not be copied to the desktop.

By the way these are the entitlements I’ve added to the build.settings file:

osx = {
    	entitlements = {
        	["com.apple.security.files.user-selected.read-write"] = true, -- get arbitrary access?
    	},
	},

I guess I need more or different entitlements, but I have no real idea… I’ve build the app with my credentials and provision profile as apple developer…
Any ideas how to fix this? I would really appreciate any help.