That is a fairly convoluted way of creating a KML file. It is likely that the elements being created do not conform super strictly to the standard and are being stripped out.
To debug this, I would recommend creating a normal KML file with polygons, lines and markers using Google Earth and then compare the text of the file to see what is different. You may just need to specify styling or something simple like that.
Another thing is that our KML input parser does not handle heavily nested objects very well. You may just need to copy some stuff around to make all the shares you are interested in at the top level of the file.