To find when you both would have knitted the same amount of rows, you will list the multiples of the numbers 5 and 8. The reason is that you knit this many each minute.
5, 10, 15, 20, 25, 30, 35, 40 (after 8 minutes)
8, 16, 24, 32, 40 (after 5 minutes)
You and your friend will knit the same number of rows after 8 minutes for you and 5 minutes for your friend.