How does the brain know what to remember and what not?
The body of work on this topic huge, so I'll just try to mention a few things.

On the cognitive level, one possible answer is salience (also see here for an article specific to the visual system). You can think of this (in a somewhat circular answer) as the thing that makes certain stimuli stand out from others. Salient stimuli capture bottom-up attention. Another possible answer is top-down attention. This is where you actively/deliberately pay attention to something.

In terms of mechanism, we have to think about different types of memory. For example, there are separate long-term and short-term memory systems (among many other distinctions). In general, there are hypothesized gating mechanisms that determine the information that can enter memory. The gating systems are controlled by some signal that says 'store this information' or 'ignore this information'. Different memory networks can have different gating systems.

There's a lot of work looking at neuromodulators as gating signals. Dopamine and acetylcholine are some prominent examples. For example, people have found that dopamine can modulate synaptic plasticity (the strengthening and weakening of connections between neurons, which is thought to be a primary mechanism of long term memory storage). It can also cause cortical remodeling. For just a couple examples, see:


  Zhang et al. (2009) Gain in sensitivity and loss in temporal contrast
  of STDP by dopaminergic modulation at hippocampal synapses.
  
  Bao et al. (2001) Cortical remodelling induced by activity of ventral
  tegmental dopamine neurons.
  
  Froemke et al. (2007). A synaptic memory trace for cortical receptive field plasticity.


On the behavioral level, stimulating the dopamine system can induce particular forms of learning (which you can think of as a form of memory). For example, if you stimulate the dopamine system, an animal may tend to repeat the behavior that led to the stimulation. A pathological version of this is thought to be what happens during addiction with certain classes of drugs that stimulate the dopamine system (e.g. cocaine, but not lsd).

Interestingly, many of the same mechanisms appear to work across species, from sea slugs to humans). Although,sea slugs can't remember going to a shop after work.