If you work in an environment where everyone is busy and working hard you will tend to work hard yourself. There will be fewer distractions and your work level will be visible to others.
At break time, you can take a trip to the water cooler or coffee machine and have some social interaction with others - discussing work issues or last night’s football.
If you work from home, you miss out on this collective, productive environment snd leave yourself open to lots of potential distractions. If you are not naturally single-mined and laser focused, you need to find ways of keeping your mind on the task in hand. (It helps, of course if the task is inherently interesting and you have ready access to all the information and tools you need to complete the task.
If you need help with focus, try the 20 minute promise. Set a timer for 20 minutes and promise yourself to maintain task focus until the timer runs out. Then give yourself a tiny reward - a biscuit (or something less sugary.). Then repeat the process.
The simple answer is to put yourself in situations where distractions are minimised and hard work is the norm and the role model.