Modified your code and it works. Following is only a part where I modified the code. Need some more improvements though.
if(!propertiesLayer)
{
timeline.addNewLayer("properties");
layerIndex = timeline.findLayerIndex("properties");
propertiesLayer = layers[layerIndex];
timeline.setSelectedLayers(0);
document.addNewText({left:0, top:-100, right:100, bottom:0});
document.setTextString("test");
var element = document.selection[0];
document.selection[0].textType = "dynamic";
element.name = "properties";
}