Serial Monitor stops working when using PinMode
My issue was that pin 7 was connected to the reset pin on the Arduino, meaning every time it was set to output, the Arduino was reset.
You can see this here:
void setup() 
{
  Serial.begin(9600); 

  Serial.println(&quot;a&quot;);

  delay(100);
    
  pinMode(7, OUTPUT);
}

void loop() 
{
  Serial.println(&quot;test&quot;);
}

which outputs a stream of a's separated by 100ms (plus a bit)