If I understand you right, you want to create the file 'filename.txt' inside the folder you just made ('folder')?
Given that's the case, use os.path.join()
import sys
filename = open(os.path.join('folder','filename.txt'),'w')
sys.stdout = filename
Now sys.stdout points to the file which is inside the new folder