Are you using a bufferedPrintWriter?   that's probably a different flushing behaviour.  Try doing out.flush() after out.write(...) and you will have the same result. 

This is Spark unrelated btw.

-kr, Gerard.