In colab I can write the contents of a cell into file like so
%%writefile Testtext.txt blah blah blah
This will produce a text file with 'blah blah blah'
But when I try to write it into my Google drive like so
%%writefile gdrive/My Drive/Testtext.txt blah blah blah
I get this error
UsageError: unrecognized arguments: Drive/Testtext.txt
My drive is mounted.
As an alternative, You can change the directory to google drive
%cd /content/drive/My\ Drive
and use %%writefile