Atmega32u4 mini - button with alternative ground

A while ago I made some mouse jigglers using a leonardo, proximity sensor for auto operation, button to switch between off, auto and on and a multi colour LED to show the mode.

Works great whilst working at the desk but I want a miniaturised version to take on the road. I've sourced a tiny atmega32u4 on a usb plug from ebay. In the interest of space and to avoid using links or resistors, I want to use two digital pins for the momentary push button I'm using and have found this code:

const byte groundPin = 9;
const byte switchPin = 11;
pinMode(switchPin, INPUT_PULLUP);
pinMode(groundPin, OUTPUT);
digitalWrite(groundPin, LOW);

tl;dr is this a safe configuration or do I risk damaging the board? I think the INPUT_PULLUP negates the need for a resistor. The tutorials I found always include ground.

Thanks

Why would you want a ground pin that you can take HIGH?
Is that to save energy during some sleep mode?

You'll have to excuse my ignorance - I'm very much a novice. Saving energy is not important. I was trying to avoid using a resistor and also having to solder a link to the ground pin. I came across the INPUT_PULLUP which I think means the input pin will be HIGH when the switch is open.

Yes, that's exactly how it works. If you use INPUT_PULLUP, you don't need an external pullup resistor.

It is OK to use the output pin to connect to an input pin, either through a button or directly. The danger you could have is configuring both pins for OUTPUT pins and then having one HIGH and one LOW somehow. If that is a possibility, you could protect the chip from the short with an external resistor to limit the current flowing between the pins.

Many thanks for the explanation.

better you don't use the code without understanding its purpose.
do you need button? switch pin in INPUT_PULLUP and when it's connected to GND you'll know it's state is LOW now and it doesn't matter how you made that connection, via a button, a switch, a straight wire to GND, or a screwdriver.

Is there a reason why you can't use the normal GND?