A 28-year-old woman presents with a 2-week history of persistent dry cough, night sweats, and a 3kg weight loss. She emigrated from a country with high TB prevalence 2 years ago. A chest X-ray shows bilateral upper lobe infiltrates with cavitation. What is the most important initial diagnostic test to confirm active pulmonary tuberculosis?