I'd use a couple of angle stretcher plates - the slots on the side for wall fixing, and the holes on the side to fix into the top of the unit.
Anyone who has ever built a flat-pack kitchen base unit will have several surplus items of this type.
Mark the hole and make a pilot hole with a bradawl or small blade screwdriver, nail, etc., on the top of the unit in a position where it will not be seen to one side of the top, and repeat on the other side.
First screw through one hole into one side of the top of the unit (presumably chipboard/MDF/Timber) with a 15mm chipboard screw, assuming 18mm chipboard. Fix another to the other side of the top using a single screw.
Make sure that there is some weight in the unit to flatten the carpet underneath. Lean the unit to the wall so the brackets lie flush with the wall.
Mark only the vertical slot locations on the wall. The screw to the unit can be loosened to allow access to the wall, and then the second screw fitted after the wall fixing is in place.
To anchor to the wall, "self drill metal plasterboard fixings" can be used. An old 6mm diameter screwdriver, rather than a drill, can be used to make an accurately placed pilot hole in the plasterboard, and to ensure that the depth of the screw can be accommodated in the blockwork beneath.
A gobbet of Gripfill can be piped into the hole for additional strength.
With a Pozidriver, screw the metal plasterboard fixings into place until secure and almost flush with the wall, do not overtighten!
Fix the remaining screws to the plates on the unit and tighten. Use the supplied screws to tighten the brackets to the plasterboard fixing.
No wandering drills, very little mess.