No need to store output in txt file directly dump it to CER (.cer). Later if you want to convert to other format use openssl x509
echo | openssl s_client -connect www.openssl.org:443 -showcerts > out.cer (echo will avoid waiting for you to terminate the connection)
You can import this certificate to your keystore/ truststore