I would suggest two things.
- Switch the magnet polarity, and see if the sensor responds better.
- Use a stronger external pull up (4.7K) instead of the internal pullup you enabled with
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH);
//equivalent to pinMode(switchPin, INPUT_PULLUP);