When you iterate over the same file twice you can use line numbers as convenient indices; it can make for cleaner logic.
awk 'NR == FNR {if ($2 in z) { y[z[$2]]; y[FNR] } z[$2]=FNR; next} (FNR in y)' file file
I used a similar trick in my answer to this question:
- Print only unique lines that appear last in logfile based on date/timePrint only unique lines that appear last in logfile based on date/time
The basis of this trick is that Awk will create a variable simply by referencing it, and the index in arrayname construct returns true or false depending on whether an array element has been created with the specified index.