Creating XML file from javascript button

How can an XML file be created in source folder from a javascript button please.

found this code somewhere but it is logging an error 'Permission denied'

    clickData.func.command.RunCommand("cd {sourcepath}");
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var a = fso.CreateTextFile("testfile.txt", true);
    a.WriteLine("This is a test.");
    a.Close();

You need to give the full path to CreateTextFile.