When a magnetic needle is suspended freely in uniform magnetic field, the two poles of the needle will experience equal and opposite forces hence net force is zero. On the other hand, when an iron nail is placed near a bar magnet, the magnetic field of bar magnet is non-uniform and the two poles of the iron nail will experience different force.