Q:

Why does my circuit work only when I do not use the Serial port?

I am a newcomer to working with Arduinos (and circuits in general) so when I was tasked with making a simple push-button circuit to control an LED's state, and to send a message back using Serial.println() to show the button had been pressed, I noticed that the LED is dimly lit when I press the button to give it power. However, when I do not use the Serial port at all in my code, then it works perfectly as expected. 
My code: 
const int ledPort = 8; 
const int detPort = 7; 
void setup() {
  pinMode(ledPort, OUTPUT); 
  pinMode(detPort, INPUT); 
  digitalWrite(ledPort, HIGH); 
  Serial.begin(9600); 
}

void loop() {

  if (digitalRead(detPort) == HIGH) {
    digitalWrite(ledPort, LOW);
    Serial.println("9"); 
    delay(500); 
  }
  else {
    digitalWrite(ledPort, HIGH); 

My circuit: 
https://imgur.com/a/evP1O40
My Board: MEGA2560

A:

Your circuit is wired improperly.
It will be easiest for you to simply follow this official tutorial that will show you how to use a push button to turn on an LED. Even though you have a mega, it will work fine for you.
You will see a wiring picture there that is simplified:

Plus, the correct code is there:
/* Basic Digital Read
 * ------------------ 
 *
 * turns on and off a light emitting diode(LED) connected to digital  
 * pin 13, when pressing a pushbutton attached to pin 7. It illustrates the
 * concept of Active-Low, which consists in connecting buttons using a
 * 1K to 10K pull-up resistor.
 *
 * Created 1 December 2005
 * copyleft 2005 DojoDave <http://www.0j0.org>
 * http://arduino.berlios.de
 *
 */

int ledPin = 13; // choose the pin for the LED
int inPin = 7;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
}

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH);  // turn LED ON
  }
}

Schematic Is Quite Important
also, as you attempt to look at the picture and build the circuit you discover how difficult it is to see how things are connected.
That leads you to understand how important a simple schematic can be.
I've attempted to turn the pic from the arduino site into a schematic and my interpretation may be wrong or the actual circuit that the Arduino site has built may be wrong.  If anyone has comments I will take them into account.
Trying to build from a picture of a circuit is terribly difficult and trying to debug your circuit from a picture is also. That's why when you submit a question you should submit a drawn schematic of how you have wired it up.

simulate this circuit – Schematic created using CircuitLab

