Updated script to export .txt file