This question is similar to AppleScript set directory path in Finder but the answer there did not work for me!
local destination, libraryName, f
set destination to "/Users/bryandunphy/Music/Result"
set libraryName to "Testing"
if not ((libraryName ends with ".xml") or (libraryName ends with ".XML")) then set libraryName to libraryName & ".xml"
menuClick({"iTunes", "File", "Library", "Export Library…"})
set f to "/Users/bryandunphy/Music/Result/Testing.xml" -- (destination & "/" & libraryName) as string
tell application "Finder"
if POSIX file f exists then
delete f
beep
end if
end tell
tell application "System Events" to tell process "iTunes" to tell its front window to set the value of its text field "Save As:" to libraryName
if switchDir(destination, "iTunes", true, true) then return destination & "/" & libraryName -- first true = click default (Save) button, last = create path if needed
The "if switchDir" line causes a "File Exists, Replace?" dialog to appear.