Your FileChooser is on the stack, whereas it should be cached somewhere. It is destroyed right now at the end of the buttonClicked call. There’s a simple example into the documentation with a global variable.
FileChooser
buttonClicked
https://docs.juce.com/master/classFileChooser.html
See Also: