Laser works when connected to 5v and 3.3v pins, but not an output pin

It's a green 5mW laser diode on an Uno board.

Draws too much current for an output pin. You will damage the output pin if you continue. Or, you may already have damaged the pin. You will need a transistor switch. Some examples shown below.