The '$cur eq $nxt' test will always compare an entry with itself at some time during each execution of the loop, thus finding a false duplicate. However, the print is driven by $count, which scopes within a state, which has the effect also of hiding the duplicate test. In a correct solution, duplicates need to be detected across states and the print needs to address a uniquified list of everything that was found in a successful duplicate test.
Update: As the other replies suggest - this uniquify idea is best implemented in a summary hash that matches your output.