Is it really necessary to create the file on the filesystem? Have you tried to work with StringIO?