Haskell, 67 58 bytes
foldl1(#)
(a:b)#(x:y)|a==x=a:b#y
c#z|(1<$c)>(1<$z)=c|0<1=z
-9 thanks to AnttiP mixing pattern failure and guard failure
Test harness truncates to run all the cases in one go, but it can be run infinitely.
Since the algorithm may be non-obvious and not everyone can read Haskell:
Explanation
foldl1 (#)
The function submission operating on a list of lists just reduces the list by a function of two lists, the infix operator #
. (Since the input is guaranteed non-empty, foldl1
won't error.)
(a:b) # (x:y)
| a == x = a : (b # y)
The critical part for handling duplicate infinite lists: if the first element of both lists is the same, then put that element in the output list and recur on the remainders of both.
c # z
| (1 <$ c) > (1 <$ z) = c
| otherwise = z
And here's the part that actually takes the longest list, if the previous clause failed. Since one of the lists can still be infinite, an actual length comparison is out of the question, but replacing every element of both lists with 1, a lexicographic comparison will terminate as soon as it reaches the point where one list ends and not the other.