There is no way to eliminate luck in science. Even the assignment of reviewers to one's grants and papers can have an important influence on one's ultimate success.
When I was a physicist, I got some very odd readings in some of my experiments. We tried varying key parameters, replicated them and always got the same fascinating results. However, other labs had trouble finding the same thing and, as a result, I never published these results. It's good thing -- the error was finally detected in the analysis software!! Was it bad luck that the software had a bug in it for the exact type of data we had but worked well on the standard testing samples? Of course, with enough work or a flash of insight the bug might have been detected with less work. But ruling things out starts from most likely to least likely and, in this case, we guessed wrong.
So the best one can do is to work hard, focus on the best betsand roll with the punches. I'll leave you with a quote from physioprof (that I thought was the best take on the issue so far):
I hate that saying as well, because it doesn’t capture the most important aspect of “attracting good luck”. In order to maximize your chances of getting lucky, you need to maximize your exposure to beneficial risk. This has much more to do with the judicious application of hard work in wisely chosen directions than it does the sheer volume of hard work.