Create new (.url) file with url address as variable input
I wrote this thinking that you were looking to create the the Mac Version of a .URL file, which would be a .webloc file...  But after reading your code, it seems my assumption was wrong.  I put too much effort into my solution to just scrap it, so in the event that you need to automate the creation of .webloc files, in the future... Here you go

This AppleScript code works for me using the latest version of macOS Mojave.

set theURL to text returned of (display dialog "Enter Desired URL" default answer ¬
    "https://stackexchange.com" buttons {"Cancel", "OK"} ¬
    default button "OK" cancel button "Cancel" with title "Enter Desired URL")

try
    tell application "Finder" to tell its window 1
        set theFolder to POSIX path of (target as alias)
    end tell
on error errMsg number errNum
    set theFolder to POSIX path of (choose folder)
end try

tell application "Finder"
    activate
    set theName to text returned of (display dialog "Enter Desired Name" default answer ¬
        "File Name" buttons {"Cancel", "OK"} ¬
        default button "OK" cancel button "Cancel" with title "Enter Desired Webloc File Name")
    set fileExists to exists of alias ((theFolder &amp; theName) as POSIX file as text)
    repeat while fileExists is true
        activate
        set theName to text returned of (display dialog "A File With That Name Already Exixts. Please Choose A Different Name" default answer ¬
            "File Name" buttons {"Cancel", "OK"} ¬
            default button "OK" cancel button "Cancel" with title "Enter Desired Webloc File Name")
        set fileExists to exists of alias ((theFolder &amp; theName) as POSIX file as text)
    end repeat
end tell

tell application "Finder" to make new internet location file at POSIX file theFolder to theURL with properties {name:theName}