Scratch all that - I finally got it.
I was missing:
$resultObject.Messages.add("Some Value")
And then call
$resultObject.toxml() | out-file $args[0];