Sounds like a loose connection of wiring or possibly a filament in the bulb that is intermittently detaching. Replace the bulb, check the wiring and connection and recheck operation.
RepairPal Certified shops can diagnose and repair your 2006 Nissan Altima. They provide transparent pricing with a minimum 12-month or 12,000-mile warranty on repairs and services.