I wanted to add a layer through the toolbox using arcpy. The below script works fine through the python console in ArcMap, but does not when executed through the toolbox. The layer flashes for a second in the layer management window and disappears. This looks very unlikely and I am not able to figure out how it could not work in the toolbox. Let me know if I had missed something.
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
sourceLayer = arcpy.mapping.Layer('C:/WIP/Shape files/KARTHIK.TEST_TABLE.lyr')
arcpy.mapping.AddLayer(df,sourceLayer,"TOP")
arcpy.RefreshActiveView()