Why is this FFT code not working to extract frequencies from a wav audio?
Your DFT is working as expected at extracting frequency information.  One musical note at one pitch usually contains a lot of spectral frequencies: from harmonics and overtones plus broadband noise from any transients, such as note attack and decay.  Furthermore, the max magnitude frequency from an actual sound recording is often not the same as the heard note pitch frequency (one possibility is the magnitude peak is instead a strong overtone).

Instead, search for pitch detection/estimation algorithms.  The good (working, more reliable) ones will do a lot more than just an FFT peak magnitude search.