For multiple lines of URScript you need to change
// Send command
out.writeUTF(thisCommand);
System.out.println("Send this: "+thisCommand);
out.flush();
to
// Send command
out.writeBytes(thisCommand);
out.write(thisCcommand.getBytes(“US-ASCII”));
out.flush();
see also here