How can I stop AppleScript from converting variables like "\087" into their octal form when passing through bash?
It looks like do shell script is running the script under the sh shell, which is actually bash in compatibility mode; in this mode, the builtin echo command apparently thinks it needs to interpret some escape (backslash) sequences. This is one of several features of echo that aren't consistent between versions/modes/etc; as the POSIX standard for echo says, "It is not possible to use echo portably across all POSIX systems unless both -n (as the first argument) and escape sequences are omitted."

So, my first recommendation is to use printf '%s\n instead of echo (and the backslash will need to be doubled to get it past AppleScript):

do shell script "printf '%s\\n' \"&lt;?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?&gt; &lt;scratch project=\\\"TEST\\\"&gt; &lt;file&gt;W:\\Sequences\\087_TLD_TL_Taking_The_Lead\\Shots\\TLD0640\\Versions\\MOV\\TLD0640_v0173.mov\\&lt;/file&gt; &lt;/scratch&gt;\" &gt; ~/Desktop/Test.xml"


But even with echo getting into the act, you still have multiple confusing levels of quotes and escapes due to interpretation by AppleScript and the shell. I'd recommend storing the XML as an AppleScript variable (using just a single level of quoting/escaping, for consumption by AppleScript), then using quoted form of to quote/escape that for use in the shell command:

set XML_Content to "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt; &lt;scratch project=\"TEST\"&gt; &lt;file&gt;W:\\Sequences\\087_TLD_TL_Taking_The_Lead\\Shots\\TLD0640\\Versions\\MOV\\TLD0640_v0173.mov\\&lt;/file&gt; &lt;/scratch&gt;"

do shell script "printf '%s\\n' " &amp; (quoted form of XML_Content) &amp; " &gt; ~/Desktop/Test.xml"