mkdir creates a directory, not a file. It's trying to create a subdirectory (what you intended to be a file) under a directory that doesn't yet exist. It then creates that parent directory, your original intention. Create the file as a seperate step after creating the directory.