Yes, it should be vented to the exterior of the house. Do not vent a dryer into an attic because the warm, moist air will increase the level of humidity there, which could lead to moisture damage and wood rot. Whenever possible, locate the dryer closest to where the vent pipe will exit the house. Use flexible 4-inch pipe or smooth sheet metal, but note that in some areas flex pipe is no longer permitted. Kits for fastening and extending the pipe through walls are available at hardware stores.
Vent pipes can go down through the floor as well as up.
If the pipe goes into a basement or crawl space, continue it to the nearest foundation vent. The pump on the washing machine may be just too powerful for the size of your drain, throwing more water than the pipe can handle. Solutions aren't easy. Installing a larger drain line is expensive. If possible, let the washer drain into a nearby large sink.