How to prepend to text file in AppleScript?
You could copy the current content of the file to a variable, then copy TextToWrite to TargetFilePath and then append the previous content back to TargetFilePath.

set x to (do shell script "cat " &amp; quoted form of TargetFilePath)

do shell script "echo " &amp; quoted form of TextToWrite &amp; " &gt; " &amp; quoted form of TargetFilePath

do shell script "echo " &amp; quoted form of x &amp; " &gt;&gt; " &amp; quoted form of TargetFilePath