Do not change the active data frame in Geoprocessing scripts. Before a geoprocessing tool runs, it takes a snapshot of the active data frame's layers, and then restores it when it finishes executing. By changing the active data frame in between the snapshot and the restore, it gets into a confused state and may drop layers.