An LCD will show blocks like that if it isn't initialized correctly. You may have an intermittently-bad connection on one or more of the control lines.
To diagnose intermittent connections, you could run a sketch that repeatedly initializes the LCD and then displays different sets of characters for a few seconds. This will allow you to wiggle different pins and find out which is responsible for the bad connection.
To avoid intermittent connections, you could use a shield with soldered pins, or could get multipin shells to replace the single-pin shells of the Dupont-type connectors shown in the photograph. Having adjacent connectors fixed in a single multipin shell results in more-stable connections.