Encourage student to participate without him helping too much
You can have some tasks where they each do the same thing (as you've been doing), but also some tasks where they need to do different things.  For example, have them write different functions that are both necessary in a larger program.  If you choose the tasks carefully, X will be too busy with his own work to meddle with Y's.