Shot in the dark, but did you try setting "False" to get the geometric extent instead of symbolized extent?
d.extent = l.getExtent(False)
I doubt that would be an issue, but like I said, shot in the dark.
Another thing, will there always be a selection? There is another method to get an extent of selected features.
d.extent = l.getSelectedExtent()
You could also try getting just the layer you want instead of going through all of them recursively,
l = arcpy.mapping.ListLayers(mxd, "Rail Roads", d)[0]