I often tell students and other new writers that writing is one part science and one part art. The first part can be codified and learned, the second has to be learned through trial and error, or experimentation. Where we write is part of that experimentation.
The where is a very personal thing, although many outside factors influence the ideal versus the reality. Some are best in a set place apart from everything where it is quiet. Others want a quiet place surrounded by books and pictures for inspiration. Some work best at home, others at an office, others in crowded coffee shops. Some are best off outdoors, some indoors.
Lighting can come into play, whether natural or artificial, a lot or a little. Even time can matter, whether morning, afternoon, or evening. Every variable is something to play with or tweak.
Music is a huge subject of discussion. I know people who can only write to music without lyrics (classical, jazz) or lyrics they can’t understand (Italian opera, German opera). Others prefer no sound. Some like loud music, others soft.
And some people can write anywhere, whether by natural inclination or necessity.
A number of outside factors can force us to adapt or work outside our ideal. Work, spouses, kids, living situations, roommates, and the like can all push us out of the ideal writing environment. Even writing advice columns can push at us to change our habits (because some famous writer said “the ideal writing environment is . . .”, we decide that must be true; the thing to remember is what is true for Famous Writer A is not true for Famous Writer B or for you). At the moment, I am writing this up at the dining room table while my toddler eats his lunch . . . not my ideal environment, but there you go.
There is also a difference between taking notes (which can happen whenever inspiration strikes) and actual writing (turning those notes into stories, articles, etc.).
Personally, I’ve taken notes on the couch while watching TV, outside while hiking, in stock rooms, in library stacks, at the dining room table, in the car, at a desk between student clients, and basically anywhere and everywhere. For actual writing, I favor a desk or table (home or work office) with music (the louder, the better). For music, I’ve found I generally write better to metal, punk, and grunge, regardless of whether I’m writing fiction or non-fiction. I do prefer a neat workspace, but have worked on messy, shared desks in shared offices. I prefer writing in the afternoon, but having a toddler basically forced most of my writing into the evening and late night (which is fine; as a night owl, I adapt). Most of my non-fiction book was written on the dining room table, late at night after everyone else in the house had gone to bed. On the other hand, my dissertation was written at my home office desk entirely in afternoons. Both turned out pretty decent.