I do not know of and couldn't find a script that does this already but it would be certainly possible to write one. After Effects doesn't have a functionality built-in for that.
With the help of ExtendScript you can write very powerful extensions for After Effects and its very easy to get going with it. Just open up the "Adobe ExtenScript Toolkit" that gets installed with every CS suite and load up an example for After Effects and have a look at the JavaScript documentation. While you can also script with AppleScript and Batch Script the documentation for the JavaScript version is a lot better.
You can access it under the "Help" menu. Most importantly look at the After Effects Scripting guide. It can be found for different CS/CC versions here.
What I would do is start to iterate through all your compositions, grab the current composition in your iteration, get an array of all the layer names in that composition and then iterate with that array through all compositions and compare the array with the array of all the other compositions. Best to not sort the arrays in case you used generic names for layers and unique layer ordering is important.
Unless you have micro changes in your duplicate comps like changed property values and keyframes this approach would be effective.
If you do have micro changes you would, after having fetched all comps with duplicate layers, also have to access every layer in your array and compare every property with the corresponding layer in the other comp.
You then delete all true duplicates of a comp and while doing that replace them with a link of your now unique comp in all occurrences in other comps.
Shouldn't be much code but it could take some time to write if you have never used Adobe ExtendScript.
On another note, a very helpful plugin to keep the composition import madness at a minimum is BAO Dynamic Comp.