Gradient flows with wiggly potential: a variational approach to the dynamics