I use construct 3 but I assume 2 works quite the same.
I think both mushrooms gets picked because the condition becomes truthy for both.
A global variable will probably not be the best way to solve this.
If the mushroom is already in the layout behind the box, in the action for the collision condition between Mario and the box, pick the mushroom closest to the box.
If you feel a variable is needed then a instance variable is more suitable.