If you want to choose the location where the file will be saved you can use the method asksaveasfile module tkFileDielog, simply import the necessary libraries from the TKinter.
Here is an example for you:
import Tkinter, tkFileDialog
def salvaarquivo(texto):
f = tkFileDialog.asksaveasfile(mode="w", )#A foi opcao definida para escrita.
if f is None:
return
f.write(texto)
f.close()
salvaarquivo(raw_input("Digite um texto para ser salvo:"))
Documentation of tkFileDialog.
Source.
Note: In case you don’t have the TKinter installed on your machine, you can download it and urge it following the instructions of the website of TKinter.
It worked on Pycharm, but on qgis it returns None...but thanks for the help anyway
– Guilherme Lima