You are using the file name as the name of the directory and then trying to write to it as if it was a file. You need to create the folder without the appended file name, thus:
if not os.path.exists(mypath):
print"Path is created"
fname = mypath + "/" + "test.txt"
with open(fname,"w") as x:
x.write("This is a boy")