I found out that all I needed to do with re-install the audio drivers on my laptop, after that the above code saved microphone input to file.