Phylogeny is the history of how a behavior evolved in a species.
Little is conclusively known about the phylogy of penis fencing, although it is possible that penis fencing evolved from a behavior evident in many close relatives of the Pseudoceros bifurcus flatworm.
The Pseudoceros bifurcus is by no means the only species of flatworm to exhibit penis fencing but that does not mean that all flatworms engage in penis fencing (Michiels & Newman 1998, Michiels & Streng 1998). Many species of flatworms and other hermaphroditic animals, such as the Cantareus aspersus terrestrial snail, engage in mutual sperm transfer (Michiels & Streng 1998, Chase & Vaga 2006).
Mutual sperm transfer is a strategy in which two individuals each donate sperm to each other. Thus both individuals play the role of the male and the female (Michiels & Bakovski 1999).
That other species within the same family as the Pseudoceros bifurcus flatworm and closely related families engage in mutual sperm exchange but only a few varieties of flatworm engage in penis fencing suggests that is evolved after mutual sperm exchange.
However, studies by Vreys and Michiels have also been done to explore the volume of sperm traded between hermaphrodicitc flatworms that engage in mutual penis intromission. They concluded that flat worms will continue to transfer sperm untill the individual with the least amount of sperm stops. Then the other individual will stop too. In other words, flatworms will give as much sperm as they get. They speculate that this is a consequence of the high cost of producing sperm. Evolution has selected for flatworms that are able to control the amount of sperm they donate based on their partners reproductive state. (Vreys & Michiels 1998).
This may suggest that mutual sperm exchange is actually more complex then penis fencing. In penis fencing individuals do not seem to have control over how much sperm is contributed. Afterall panis fencing is essentially a fight to have the opportunity to donate sperm. When an individual has a chance to donate sperm he does not appear to be regualting as sperm does not always end up in the ovaries of the other flatworm. There have been many examples of accidental insemination on the wrong side of the "female" (Michiels & Streng 1998).
It could be hypothesised that mutual sperm exchange evolved in marine flatworms that were able to control the amount of sperm deposited and that penis fencing is just present in species that have not developed this way. Of course it could also be hypothesised that both mutual sperm tansfer and penis fencing have evolved from the same behavior that is longer present but that each diverged seperatly from it. To fully understand the phylogeny of this behavior it would be neccesary to look at a phylogenetic tree of not just marin flat worms but snails, leeches and sea slugs. Unfortuantly there are so many species within each of these families that a tree of this scope has not been examined.